﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class UserWork_Plan_user_ReadPlan : System.Web.UI.Page
{
    BLL.B_Dictionary bll = new B_Dictionary();
    BLL.B_UserPlan bllplan = new B_UserPlan();
    BLL.B_Login blllogin = new B_Login();
    protected void Page_Load(object sender, EventArgs e)
    {
        string strLogin = Session["LoginName"].ToString();
        if (!IsPostBack)
        {
            cboEmployeeDataBinding(strLogin);
            //SelectTodayPlanAllEmployee(strLogin);
        }
    }
    public void cboEmployeeDataBinding(string strLogin)
    {
        cboEmployee.DataSource = bll.getEmployee(strLogin);
        cboEmployee.DataBind();
    }
    //private void SelectTodayPlanAllEmployee(string strLogin)
    //{
    //    IList<M_userPlan> lst = bllplan.GetIListForManager(strLogin);
    //    if (lst != null && lst.Count() > 0)
    //    {
    //        rpPlan.DataSource = lst;
    //        rpPlan.DataBind();
    //    }
    //}
    private void SelectTodayPlanOneEmployee(string strLogin,DateTime dt)
    {
        IList<M_userPlan> lst = bllplan.GetListForManager(strLogin, dt);
        rpPlan.DataSource = lst;
        rpPlan.DataBind();
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        txtUser.Text = "";
        txtManager.Text = "";
        if ((cboEmployee.Text.Trim() != "") && (txtDt.Text.Trim()!=""))
        {
            string strEmployee = cboEmployee.Text.Trim();
            DateTime dt = DateTime.Parse(txtDt.Text.Trim());
            SelectTodayPlanOneEmployee(strEmployee, dt);
            IList<string> ilst = bllplan.GetRemark(strEmployee, dt);
            if (ilst.Count > 0)
            {
                txtUser.Text = ilst[1].ToString();
                txtManager.Text = ilst[0].ToString();
            }
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        if (this.txtDt.Text.Trim() != "" && this.cboEmployee.Text.Trim() != "")
        { 
            string strManagerRemark = this.txtManager.Text.Trim();
            string strUserRemark = this.txtUser.Text.Trim(); 
            string strUser =this.cboEmployee.Text.Trim(); 
            DateTime dt = DateTime.Parse(this.txtDt.Text.Trim());
            if (bllplan.UpdateUserPlanM(strManagerRemark, strUserRemark, strUser, dt) == 1)
            {
                Response.Write("评论成功");
            }
            else
            {
                Response.Write("评论失败");
            }
        }
    }
}